package edu.zqu.course.project.controller;


import edu.zqu.common.result.ZQUResult;
import edu.zqu.course.project.domain.pojo.CourseSyllabusDescription;
import edu.zqu.course.project.service.CourseSyllabusDescriptionService;
import edu.zqu.course.response.SessionShow;
import edu.zqu.course.response.SessionShow01;
import edu.zqu.course.response.TeachingProgram;
import edu.zqu.course.response.TeachingProgramDetail;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 课程大纲内容，即：章 前端控制器
 * </p>
 *
 * @author 郭泽鹏
 * @since 2020-06-24
 */
@RestController
@RequestMapping("/course-syllabus-description")
@Api(tags = "课程大纲内容，即：章 前端控制器")
public class CourseSyllabusDescriptionController {
    @Resource
    CourseSyllabusDescriptionService courseSyllabusDescriptionService;

    /**
     *
     * @return
     * 查询操作
     */
    @GetMapping("/list")
    @ApiOperation("查询所有")
    public ZQUResult getCourseSyllabusDescriptionList(){
        List<CourseSyllabusDescription> courseSyllabusDescriptionList = courseSyllabusDescriptionService.getCourseSyllabusDescriptionList();
        return ZQUResult.success("查询成功",courseSyllabusDescriptionList);
    }

    @GetMapping("/teaching_programmer/{cs_id}/")
    @ApiOperation("教学计划：通过教学大纲id查询")
    public ZQUResult getCsdTpByCsIdAndChapter(@PathVariable(value = "cs_id") String csId,
                                              Integer page, Integer size){
        List<TeachingProgram> teachingPrograms = courseSyllabusDescriptionService.getCsdTpByCsIdAndChapter(csId, page, size);
        return ZQUResult.success("查询成功",teachingPrograms);
    }

    @GetMapping("/teaching_programmer_detail/{id}")
    @ApiOperation("教学计划详细：通过主键查询")
    public ZQUResult getCsdTpdByCsIdAndChapter(@PathVariable(value = "id") Long id){
        TeachingProgramDetail TeachingProgramDetail = courseSyllabusDescriptionService.getCsdTpdById(id);
        return ZQUResult.success("查询成功",TeachingProgramDetail);
    }

    @GetMapping("/session_show/{id}")
    @ApiOperation("节展示：通过知识点id查询")
    public ZQUResult getSessionShowById(@PathVariable(value = "id") Long id){
        SessionShow sessionShow = courseSyllabusDescriptionService.getSessionShowById(id);
        return ZQUResult.success("查询成功",sessionShow);
    }


    /**
     * 删除操作
     */
    @DeleteMapping("/list")
    @ApiOperation("删除所有")
    public ZQUResult deleteCourseSyllabusDescriptionList(){
        Integer result = courseSyllabusDescriptionService.deleteCourseSyllabusDescriptionList();
        return ZQUResult.success("删除成功",result);
    }

    @DeleteMapping("/{id}")
    @ApiOperation("通过章id进行删除")
    public ZQUResult deleteByCSDId(@PathVariable(value = "id") Long id){
        Integer result = courseSyllabusDescriptionService.deleteByCSDID(id);
        return ZQUResult.success("删除成功",result);
    }

    /**
     * 更新操作
     */
    @PutMapping("/teaching_programmer/{id}")
    @ApiOperation("修改教学计划及教学计划详细")
    public ZQUResult PutCsdTpByCsIdAndChapter(@PathVariable(value = "id") Long id,
                                              @RequestBody CourseSyllabusDescription courseSyllabusDescription){
        courseSyllabusDescription.setId(id);
        Integer result = courseSyllabusDescriptionService.putCsdTpdByCsIdAndChapter(courseSyllabusDescription);
        return ZQUResult.success("更新成功",result);
    }

    @PutMapping("/teaching_programmer_detail/{id}")
    @ApiOperation("修改节展示")
    public ZQUResult putSessionShow(@PathVariable(value = "id") Long id,
                                               @RequestBody SessionShow sessionShow){
        //将传进来的id赋值给session01Id
        SessionShow01 sessionShow01 = sessionShow.getSessionShow01();
        sessionShow01.setId(id);
        sessionShow.setSessionShow01(sessionShow01);

        Integer result = courseSyllabusDescriptionService.putSessionShow(sessionShow);
        return ZQUResult.success("更新成功",result);
    }

    /**
     * 添加操作
     */
    @PostMapping("")
    @ApiOperation("添加课程大纲内容")
    public ZQUResult insertCourseSyllabusDescription(@RequestBody CourseSyllabusDescription courseSyllabusDescription){
        Integer result = courseSyllabusDescriptionService.insertCourseSyllabusDescription(courseSyllabusDescription);
        return ZQUResult.success("添加成功",result);
    }
}

